/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package formularios;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import modelo.ModeloTabela;
import utilizador_bd.ConectBD;

/**
 *
 * @author Daniel
 */


public class Fornecedores extends javax.swing.JFrame {
      ConectBD conect = new ConectBD();
            ConectBD conectforn = new ConectBD();

private String SQL;

    /**
     * Creates new form Fornecedores
     */
    public Fornecedores() {
        initComponents();
        conectforn.conexao();
                         conect.conexao();

                 preencherTabela("select * from fornecedores order by cod_fornecedor");


    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldcodfornecedor = new javax.swing.JTextField();
        jTextField2designacao = new javax.swing.JTextField();
        jTextField3email = new javax.swing.JTextField();
        jTextField4nrcont = new javax.swing.JTextField();
        jTextField5telefon = new javax.swing.JTextField();
        jButton1novo = new javax.swing.JButton();
        jButton2guardar = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jButton1editar = new javax.swing.JButton();
        jButton2eliminar = new javax.swing.JButton();
        jButton3log = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jButton1ultimo = new javax.swing.JButton();
        jButton2primeiro = new javax.swing.JButton();
        jButton3anterior = new javax.swing.JButton();
        jButton4proximo = new javax.swing.JButton();

        jLabel6.setText("jLabel6");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Cod_fornecedor");

        jLabel2.setText("Designação");

        jLabel3.setText("Email");

        jLabel4.setText("Nr Contribuinte");

        jLabel5.setText("Telefone");

        jButton1novo.setText("novo");
        jButton1novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1novoActionPerformed(evt);
            }
        });

        jButton2guardar.setText("guardar");
        jButton2guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2guardarActionPerformed(evt);
            }
        });

        jLabel7.setText("Formulário Fonecedores");

        jButton1editar.setText("editar");
        jButton1editar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1editarActionPerformed(evt);
            }
        });

        jButton2eliminar.setText("eliminar");
        jButton2eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2eliminarActionPerformed(evt);
            }
        });

        jButton3log.setText("LogOut");
        jButton3log.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3logActionPerformed(evt);
            }
        });

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable2MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jButton1ultimo.setText("Último");
        jButton1ultimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ultimoActionPerformed(evt);
            }
        });

        jButton2primeiro.setText("Primeiro");
        jButton2primeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2primeiroActionPerformed(evt);
            }
        });

        jButton3anterior.setText("Anterior");
        jButton3anterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3anteriorActionPerformed(evt);
            }
        });

        jButton4proximo.setText("Próximo");
        jButton4proximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4proximoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jButton1novo)
                .addGap(30, 30, 30)
                .addComponent(jButton2guardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1editar)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jLabel7))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addComponent(jButton2eliminar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton3log)))
                .addGap(84, 84, 84))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel3)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jTextField3email))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField2designacao, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldcodfornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(89, 89, 89)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextField5telefon, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField4nrcont, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 628, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jButton2primeiro)
                        .addGap(38, 38, 38)
                        .addComponent(jButton1ultimo)
                        .addGap(50, 50, 50)
                        .addComponent(jButton3anterior)
                        .addGap(38, 38, 38)
                        .addComponent(jButton4proximo)))
                .addContainerGap(27, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel7)
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextFieldcodfornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2designacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextField4nrcont, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTextField5telefon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField3email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(68, 68, 68)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1novo)
                    .addComponent(jButton2guardar)
                    .addComponent(jButton1editar)
                    .addComponent(jButton2eliminar)
                    .addComponent(jButton3log))
                .addGap(28, 28, 28)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1ultimo)
                    .addComponent(jButton3anterior)
                    .addComponent(jButton4proximo)
                    .addComponent(jButton2primeiro))
                .addGap(40, 40, 40))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(22, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1novoActionPerformed
            jTextField2designacao.setEnabled(true);
            jTextField5telefon.setEnabled(true);
            jTextField4nrcont.setEnabled(true);
            jTextField3email.setEnabled(true);
            jTextFieldcodfornecedor.setEnabled(false);
            jButton1editar.setEnabled(false);
            jButton2eliminar.setEnabled(false);
            jButton2guardar.setEnabled(true);

            jButton1novo.setEnabled(false);
    }//GEN-LAST:event_jButton1novoActionPerformed

    private void jButton2guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2guardarActionPerformed
PreparedStatement pst;
    
          try {
              pst = conect.con.prepareStatement("insert into fornecedores (designacao,email,nrcontrib,telefone)values (?,?,?,?)");
         pst.setString(1, jTextField2designacao.getText());
            pst.setString(2, jTextField3email.getText());
               pst.setString(3, jTextField4nrcont.getText());
            pst.setString(4, jTextField5telefon.getText());
          pst.executeUpdate();
          
          preencherTabela("select * from fornecedores order by cod_fornecedor");
            JOptionPane.showMessageDialog(rootPane, "Salvo com sucesso!");

          
          } catch (SQLException ex) {
              Logger.getLogger(Fornecedores.class.getName()).log(Level.SEVERE, null, ex);
         JOptionPane.showMessageDialog(rootPane, "Erro na inserção!\n Erro:" +ex);  }

            jTextField2designacao.setEnabled(true);
            jTextField3email.setEnabled(true);
            jTextField4nrcont.setEnabled(true);
            jTextField5telefon.setEnabled(true);
            jTextFieldcodfornecedor.setEnabled(true);

            jButton2guardar.setEnabled(true);
            jButton2eliminar.setEnabled(true);
            jButton1editar.setEnabled(true);
            jButton1novo.setEnabled(true);
            
    }//GEN-LAST:event_jButton2guardarActionPerformed
public void preencherTabela(String SQL){
        ArrayList dados = new ArrayList();
        
        String [] Colunas = new String[]{"ID", "Designação", "NrContribuinte", "Telefone", "Email"};
        
        conect.executaSQL(SQL);
          try {
              conect.re.first();
              
                do{
         dados.add(new Object[]{conect.re.getInt("cod_fornecedor"),conect.re.getString("designacao"),conect.re.getInt("nrcontrib"),conect.re.getInt("telefone"),conect.re.getString("email")});
     } while(conect.re.next());
     
          } catch (SQLException ex) {
           JOptionPane.showMessageDialog(null, "Erro no array!\n Erro:" +ex.getMessage());
          }
          
     ModeloTabela modelo = new ModeloTabela(dados, Colunas);
     
     jTable2.setModel(modelo);
     jTable2.getColumnModel().getColumn(0).setPreferredWidth(110);
     jTable2.getColumnModel().getColumn(0).setResizable(false);
     jTable2.getColumnModel().getColumn(1).setResizable(false);
     jTable2.getColumnModel().getColumn(1).setPreferredWidth(110);
     jTable2.getColumnModel().getColumn(2).setResizable(false);
     jTable2.getColumnModel().getColumn(2).setPreferredWidth(110);
     jTable2.getColumnModel().getColumn(3).setResizable(false);
     jTable2.getColumnModel().getColumn(3).setPreferredWidth(110);
     jTable2.getColumnModel().getColumn(4).setResizable(false);
     jTable2.getColumnModel().getColumn(4).setPreferredWidth(110);

     jTable2.getTableHeader().setReorderingAllowed(false);
     jTable2.setAutoResizeMode(jTable2.AUTO_RESIZE_OFF);
     jTable2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }





    private void jButton3logActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3logActionPerformed
 int resposta ;
        
        resposta=JOptionPane.showConfirmDialog(null, "Quer mesmo sair do programa?");       

       if (resposta == JOptionPane.YES_OPTION) {

dispose();



} else {


}        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3logActionPerformed

    private void jButton1ultimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ultimoActionPerformed
conect.executaSQL("select *  from fornecedores");
          try {
              conect.re.last();
              
              jTextFieldcodfornecedor.setText(String.valueOf(conect.re.getInt("cod_fornecedor")));
              jTextField2designacao.setText(conect.re.getString("designacao"));
              jTextField3email.setText(String.valueOf(conect.re.getString("email")));
              jTextField4nrcont.setText(String.valueOf(conect.re.getInt("nrcontrib")));
              jTextField5telefon.setText(String.valueOf(conect.re.getInt("telefone")));

          } catch (SQLException ex) {
           JOptionPane.showMessageDialog(rootPane, "Erro no anterior!\n Erro:" +ex.getMessage());
          }
    }//GEN-LAST:event_jButton1ultimoActionPerformed

    private void jButton2primeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2primeiroActionPerformed
       conect.executaSQL("select *  from fornecedores order by cod_fornecedor");
          try {
              conect.re.first();
              
              jTextFieldcodfornecedor.setText(String.valueOf(conect.re.getInt("cod_fornecedor")));
              jTextField2designacao.setText(conect.re.getString("designacao"));
              jTextField3email.setText(String.valueOf(conect.re.getString("email")));
              jTextField4nrcont.setText(String.valueOf(conect.re.getInt("nrcontrib")));
              jTextField5telefon.setText(String.valueOf(conect.re.getInt("telefone")));

          } catch (SQLException ex) {
           JOptionPane.showMessageDialog(rootPane, "Erro no anterior!\n Erro:" +ex.getMessage());
          }
    }//GEN-LAST:event_jButton2primeiroActionPerformed

    private void jButton3anteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3anteriorActionPerformed
          try {
              conect.executaSQL("select *  from fornecedores order by designacao");

              conect.re.previous();
              
              jTextFieldcodfornecedor.setText(String.valueOf(conect.re.getInt("cod_fornecedor")));
              jTextField2designacao.setText(conect.re.getString("designacao"));
              jTextField3email.setText(String.valueOf(conect.re.getString("email")));
              jTextField4nrcont.setText(String.valueOf(conect.re.getInt("nrcontrib")));
              jTextField5telefon.setText(String.valueOf(conect.re.getInt("telefone")));

          } catch (SQLException ex) {
           JOptionPane.showMessageDialog(rootPane, "Erro no anterior!\n Erro:" +ex.getMessage());
          }    }//GEN-LAST:event_jButton3anteriorActionPerformed

    
    
    
    private void jButton4proximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4proximoActionPerformed
         
                      conectforn.executaSQL("select *  from fornecedores order by cod_fornecedor");

        try {
              

              conectforn.re.next();
              
              jTextFieldcodfornecedor.setText(String.valueOf(conect.re.getInt("cod_fornecedor")));
              jTextField2designacao.setText(conect.re.getString("designacao"));
              jTextField3email.setText(String.valueOf(conect.re.getString("email")));
              jTextField4nrcont.setText(String.valueOf(conect.re.getInt("nrcontrib")));
              jTextField5telefon.setText(String.valueOf(conect.re.getInt("telefone")));

          } catch (SQLException ex) {
           JOptionPane.showMessageDialog(rootPane, "Erro no proximo!\n Erro:" +ex.getMessage());
           
          }    }//GEN-LAST:event_jButton4proximoActionPerformed

    private void jButton2eliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2eliminarActionPerformed
 try {
            PreparedStatement pft;
            pft = conect.con.prepareStatement("delete from fornecedores where cod_fornecedor='" +jTextFieldcodfornecedor.getText()+"'");
            pft.executeUpdate();
                             preencherTabela("select * from fornecedores order by cod_fornecedor");

            JOptionPane.showMessageDialog(rootPane, "Eliminado com sucesso:");
        } catch (SQLException ex) {
           JOptionPane.showMessageDialog(rootPane, "Erro na inserção!\n Erro:" +ex.getMessage());
        }
        
        
        
            jTextField2designacao.setEnabled(false);
            jTextField3email.setEnabled(false);
            jTextField4nrcont.setEnabled(false);
            jTextField5telefon.setEnabled(false);
            jTextFieldcodfornecedor.setEnabled(false);

            jButton2guardar.setEnabled(false);
            jButton2eliminar.setEnabled(false);
            jButton1editar.setEnabled(false);
            jButton1novo.setEnabled(true);        
            
            
    }//GEN-LAST:event_jButton2eliminarActionPerformed

    private void jButton1editarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1editarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1editarActionPerformed

    private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
 try {
     int cod_fornecedor;
     String mail;
     int cont, telef;
     
         String nome = "" + jTable2.getValueAt(jTable2.getSelectedRow(), 1);
        conect.executaSQL("select * from fornecedores where designacao ='"+nome+"'");

        conect.re.first();
        
        
        cod_fornecedor=conect.re.getInt("cod_fornecedor");
        jTextFieldcodfornecedor.setText(String.valueOf(cod_fornecedor));
        
        mail =  conect.re.getString("email");
        jTextField3email.setText(mail);
        
         cont=conect.re.getInt("nrcontrib");
        jTextField4nrcont.setText(String.valueOf(cont));
        
        
        telef=conect.re.getInt("telefone");
        jTextField5telefon.setText(String.valueOf(telef));
        
        
        jTextField2designacao.setText(nome);
        

    } catch (SQLException ex) {
JOptionPane.showMessageDialog(rootPane, "Erro ao pesquisar na tabela!"+ex.getMessage());
        
        

        

}     }//GEN-LAST:event_jTable2MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Fornecedores.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Fornecedores.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Fornecedores.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Fornecedores.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Fornecedores().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1editar;
    private javax.swing.JButton jButton1novo;
    private javax.swing.JButton jButton1ultimo;
    private javax.swing.JButton jButton2eliminar;
    private javax.swing.JButton jButton2guardar;
    private javax.swing.JButton jButton2primeiro;
    private javax.swing.JButton jButton3anterior;
    private javax.swing.JButton jButton3log;
    private javax.swing.JButton jButton4proximo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField jTextField2designacao;
    private javax.swing.JTextField jTextField3email;
    private javax.swing.JTextField jTextField4nrcont;
    private javax.swing.JTextField jTextField5telefon;
    private javax.swing.JTextField jTextFieldcodfornecedor;
    // End of variables declaration//GEN-END:variables
}
